/*
 * @Author: 花香蝶自来 1026583651@qq.com
 * @Date: 2024-05-26 19:07:14
 * @LastEditors: xuezhuangzhuang xzz6996@qq.com
 * @LastEditTime: 2024-06-04 22:17:55
 * @FilePath: /crm/z/function/request.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

function isObject(value) {
	return typeof value === "object" && value !== null;
}
export default function request() {
	let callback;
	let promise = new Promise((resolve, reject) => {
		callback = function(resolvedata, rejectdata) {
			if (resolvedata) {
				resolve(resolvedata);
			} else {
				reject(rejectdata);
			}
		};
	});
	var arr = arguments; //参数数组
	// console.log(123456, arr);
	let defaultconfig = {
		url: "", //仅为示例，并非真实接口地址。
		data: {},
		method: "POST",
		dataType: "json",
		header: {
			"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", //自定义请求头信息
		},
		success: (res) => {
			callback(res.data);
		},
	};
	if (isObject(arr[0])) {
		defaultconfig = {
			...defaultconfig,
			...arr[0],
		};
	} else {
		let keys = ["url", "data", "method"];
		let arr2 = {};
		keys.forEach((e, i) => {
			if (arr[i]) {
				arr2[e] = arr[i];
			}
		});
		defaultconfig = {
			...defaultconfig,
			...arr2,
		};
	}

	defaultconfig.url = process.env.VUE_APP_BASE_URL + defaultconfig.url;
	// console.log(defaultconfig, "defaultconfig");
	// defaultconfig.method = "get"
	uni.request(defaultconfig);
	return promise;
}